//
//  LCAppDelegate+GDTSplashAd.m
//  JKFuYinProject
//
//  Created by jiukuyinyue on 2017/11/23.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCAppDelegate+GDTSplashAd.h"

@implementation LCAppDelegate (GDTSplashAd)


///baidu广告
-(void)loadBaiduMob{
    BaiduMobAdSplash *splash = [[BaiduMobAdSplash alloc] init];
    splash.delegate = self;
    splash.AdUnitTag = @"4927344";
    splash.canSplashClick = YES;
    self.splash = splash;
    
    //可以在customSplashView上显示包含icon的自定义开屏
    self.customSplashView = [[UIView alloc]initWithFrame:self.window.frame];
    self.customSplashView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:self.customSplashView];
//#define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
//#define arc4random_color RGBColor(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255))
//    self.customSplashView.backgroundColor = arc4random_color;//调用随机色
    CGFloat screenWidth = self.window.frame.size.width;
    CGFloat screenHeight = self.window.frame.size.height;
    
    //在baiduSplashContainer用做上展现百度广告的容器，注意尺寸必须大于200*200，并且baiduSplashContainer需要全部在window内，同时开机画面不建议旋转
    UIView *baiduSplashContainer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight - 100)];
    [self.customSplashView addSubview:baiduSplashContainer];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, screenHeight - 100, screenWidth, 100)];
    imageView.image = [UIImage imageNamed:@"gdt_splash_logo"];
    [self.customSplashView addSubview:imageView];
    
    //
    //在的baiduSplashContainer里展现百度广告
    [splash loadAndDisplayUsingContainerView:baiduSplashContainer];
    
}
- (NSString *)publisherId {
    return @"b3a6d662";
}

- (void)splashDidClicked:(BaiduMobAdSplash *)splash {
    NSLog(@"splashDidClicked");//点击广告之后会触发
}

- (void)splashDidDismissLp:(BaiduMobAdSplash *)splash {
    NSLog(@"splashDidDismissLp");
}

- (void)splashDidDismissScreen:(BaiduMobAdSplash *)splash {
    NSLog(@"splashDidDismissScreen");
    [self removeSplash];
}

- (void)splashSuccessPresentScreen:(BaiduMobAdSplash *)splash {
    NSLog(@"splashSuccessPresentScreen");
}

- (void)splashlFailPresentScreen:(BaiduMobAdSplash *)splash withError:(BaiduMobFailReason)reason {
    NSLog(@"splashlFailPresentScreen withError %d", reason);
    [self removeSplash];
}

/**
 *  展示结束or展示失败后, 手动移除splash和delegate
 */
- (void) removeSplash {
    if (self.splash) {
        self.splash.delegate = nil;
        self.splash = nil;
        [self.customSplashView removeFromSuperview];
    }
}

@end
